import { GameObject, getGameObjectById } from "../../engine";
import { cookScenePrefabBehaviour } from "../../ScenePrefabBehaviour/cookScenePrefabBehaviour";
import { xinagcaiPrefabBehaviour } from "../../prefabBehaviours/xinagcaiPrefabBehaviour";
import { Transform } from "../Transform";
import { System } from "./System";
import { startScenePrefabBehaviour } from "../../ScenePrefabBehaviour/startScenePrefabBehaviour";
import { schoolgateScenePrefabBehaviour } from "../../ScenePrefabBehaviour/schoolgateScenePrefabBehaviour";
import { changeDaysPrefabBehaviour } from "../../ScenePrefabBehaviour/changeDaysPrefabBehaviour";
import { UIPrefabBehaviour } from "../../ScenePrefabBehaviour/UIPrefabBehaviour";


export class GamePlaySystem extends System {

    scene;
    ui;
    lastscenenumber=0
    startScene 
    startSceneGameObject
    cookScene 
    cookSceneGameObject 
    schoolgateScene 
    schoolgateSceneGameObject
    changeDays
    changeDaysGameObject
    UIPrefab
    UIPrefabGameObject


    onStart(): void {
        console.log('开始游戏')
        this.scene = getGameObjectById('scene');
        this.ui = getGameObjectById('ui');
        this.startScene = new startScenePrefabBehaviour()
        this.startSceneGameObject = this.gameEngine.createNewPrefab(this.startScene)
        this.cookScene = new cookScenePrefabBehaviour()
        this.cookSceneGameObject = this.gameEngine.createNewPrefab(this.cookScene)
        this.schoolgateScene = new schoolgateScenePrefabBehaviour()
        this.schoolgateSceneGameObject = this.gameEngine.createNewPrefab(this.schoolgateScene)
        this.changeDays = new changeDaysPrefabBehaviour()
        this.changeDaysGameObject = this.gameEngine.createNewPrefab(this.changeDays)
        this.UIPrefab = new UIPrefabBehaviour()
        this.UIPrefabGameObject = this.gameEngine.createNewPrefab(this.UIPrefab)
        if(this.gameEngine.defaultSceneName=="./assets/scenes/main.yaml"){
             this.gameEngine.scenenumber=1   
        }

        //this.scene.addChild(this.startSceneGameObject)
        //this.ui.addChild(this.UIPrefabGameObject)

        // setTimeout(() => {
        //     scene.removeChild(blockGameObject)
        // }, 3000)
        // const mainRoleGameObject = this.gameEngine.createPrefab('./assets/prefabs/mainRole.yaml')
        // scene.addChild(mainRoleGameObject)
    }

    onUpdate(): void {
        
        
        // const schoolgateScene = new schoolgateScenePrefabBehaviour()
        // const schoolgateSceneGameObject = this.gameEngine.createNewPrefab(schoolgateScene)
      // if(this.gameEngine.defaultSceneName=="./assets/scenes/main.yaml"){
            if(this.gameEngine.scenenumber==1){
            console.log("加载初始场景")
            this.removeScene()       
            this.scene.addChild(this.startSceneGameObject)
            this.lastscenenumber=1
            this.ui.addChild(this.UIPrefabGameObject)
            this.gameEngine.scenenumber=0
        }
        if(this.gameEngine.scenenumber==2){
            this.removeScene()           
            this.scene.addChild(this.cookSceneGameObject)
            this.lastscenenumber=2
            this.ui.addChild(this.UIPrefabGameObject)
            this.gameEngine.scenenumber=0
        }
        if(this.gameEngine.scenenumber==3){
            this.removeScene()
            this.scene.addChild(this.schoolgateSceneGameObject)
            this.lastscenenumber=3
            this.ui.addChild(this.UIPrefabGameObject)
            this.gameEngine.scenenumber=0
        }
        if(this.gameEngine.scenenumber==4){
            this.removeScene()
            this.scene.addChild(this.changeDaysGameObject)
            this.lastscenenumber=4
            this.ui.addChild(this.UIPrefabGameObject)
            this.gameEngine.scenenumber=0
        }
       // }

        //console.log(this.lastscenenumber)
        // const cameraGameObject = getGameObjectById('camera');
        // const transform = cameraGameObject.getBehaviour(Transform)
        // transform.x += 1;
    }
    removeScene(){
        this.ui.removeChild(this.UIPrefabGameObject)
        //console.log(this.lastscenenumber)
        switch(this.lastscenenumber){
              case 0:break;
              case 1:
                this.scene.removeChild(this.startSceneGameObject)
                console.log(this.lastscenenumber)
                break;
              case 2:
                this.scene.removeChild(this.cookSceneGameObject)
                console.log(this.lastscenenumber)
                break; 
              case 3:
                this.scene.removeChild(this.schoolgateSceneGameObject)
                break;
              case 4:
                this.scene.removeChild(this.changeDaysGameObject)
                break;
        }
    }


}